package leetcode100;

import java.util.LinkedList;

public class lc048 {
    public static void main(String[] args) {

    }

    public boolean isValidBST(TreeNode root) {
        if (root==null)
            return false;
        if (root.left==null&&root.right==null)
            return true;

        LinkedList<TreeNode> stack = new LinkedList<>();
        TreeNode cur = root;
        long last = Long.MIN_VALUE;
        while(cur!=null ||!stack.isEmpty() ) {
            while(cur!=null) {
                stack.push(cur);
                cur = cur.left;
            }
            cur = stack.pop();
            if (cur.val<=last)
                return false;
            last = cur.val;
//            System.out.print("cur = " + cur);
            cur = cur.right;

        }
        return true;
    }
}
